package com.cloud.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @author cyt
 * @create 2020-03-11 21:48
 */
@Configuration
public class BeanConfig {
    /**
     *
     *
     */
    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    /**
     * 定义负载均衡算法， 使用自带的随机算法
     *
     * @return
     */
    @Bean
    public IRule myIRule() {
        return new RandomRule();
    }
}
